<!-- 雷达图 -->
<template>
  <div>
    <div>【云端报警风险】</div>
    <div class="w-full h-full" ref="target"></div>
  </div>
</template>
<script setup>
import { defineProps, onMounted, ref, watch } from "vue";
import * as echarts from "echarts";

const props = defineProps({
  data: {
    type: Object,
    required: true,
  },
});

// 1.初始化echarts 实例
const target = ref(null);
let mChart = null;
onMounted(() => {
  mChart = echarts.init(target.value);
  renderChart();
});
// 2.构建option配置对象
const renderChart = () => {
  const options = {
    // 雷达图坐标系配置
    radar: {
      name: {
        textStyle: {
          color: "#05D5FF",
          fontSize: 14,
        },
      },
      shape: "polygon",
      center: ["50%", "50%"],
      radius: "80%",
      startAngle: 129,
      axisLine: {
        lineStyle: {
          color: "rgba(5,213,255,.8)",
        },
      },
      splitLine: {
        show: true,
        lineStyle: {
          width: 1,
          color: "rgba(5,213,255,.8)",
        },
      },
      indicator: props.data.risks.map((item) => ({
        name: item.name,
        max: 100,
      })),
      solitArea: {
        show: false,
      },
    },
    // 坐标极点
    polar: {
      center: ["50%", "50%"],
      radius: "0%",
    },
    // 坐标角度
    angleAxis: {
      min: 0,
      interval: 5,
      clockwise: false,
    },
    // 径向轴
    radiusAxis: {
      min: 0,
      interval: 20,
      splitLine: {
        show: true,
      },
    },
    // 图表核心配置
    series: {
      type: "radar",
      symbol: "circle",
      symbolSize: 10,
      itemStyle: {
        normal: {
          color: "#05D5FF",
        },
      },
      areaStyle: {
        normal: {
          color: "#05D5FF",
          opacity: 0.5,
        },
      },
      lineStyle: {
        width: 2,
        color: "#05D5FF",
      },
      label: {
        normal: {
          show: true,
          color: "#fff",
        },
      },
      data: [
        {
          value: props.data.risks.map((item) => item.value),
        },
      ],
    },
  };
  // 3.通过实例.setOptions(option)
  mChart.setOption(options);
};
watch(
  () => props.data,
  () => {
    renderChart();
  }
);

console.log(props.data);
</script>
<style scoped lang="scss"></style>
